import { loadChannelAPI } from '../../api/channel';

export const getChannelListCreator = () => {
  // 2. 封装一个API、定义异步action
  return async (dispatch) => {
    const { data } = await loadChannelAPI();
    // 4. dispatch 触发保存数据的action
    dispatch({ type: 'channel/setList', payload: data.channels });
  };
};

// 3.2 定义更新current的action
export const setCurrentCreator = (id) => {
  return {
    type: 'channel/setCurrent',
    payload: id,
  };
};
